using System;
using System.Collections.Generic;
using System.Text;

namespace Scheduler
{
    /*
     * An object of this class hold the information of an appointment for a customer.
     * These information are:
     * the therapy name to be provided (String therName)
     * the name of the RMT providing that therapy (String rmtName)
     * the room the therapy will be provided in(int room)
     * the date of the therapy (TimeSlot time)
     * the price of that therapy (int price)
     */
    public class Appointment
    {
        private String therName;
        private String rmtName;
        private String room;
        private TimeSlot time;
        private int price;
        private int id;

        public Appointment()
        {
            therName = "";
            rmtName = "";
            room = "";
            time = new TimeSlot();
            price = 0;
            id = -1;
        }

        public Appointment(String rmtName, String therName, String room, TimeSlot time, int price) : this()
        {
            this.therName = therName;
            this.rmtName = rmtName;
            this.room = room;
            this.time = time;
            this.price = price;
            this.id = -1;
        }

        /*
         * This constructor builds an object of Appointment by 
         * querying the database.
         */ 
        public Appointment(Database db, int appointmentID) : this()
        {
            Appointment temp = db.readAppointment(appointmentID);
            this.rmtName = temp.rmtName;
            this.room = temp.room;
            this.time = temp.time;
            this.price = temp.price;
            this.therName = temp.therName;
            this.id = appointmentID;
        }
        public String TherapyName
        {
            get { return therName; }
            set { therName = String.Copy(value); }
        }

        public String RMTName
        {
            get { return rmtName; }
            set { rmtName = String.Copy(value); }
        }

        public String Room
        {
            get { return room; }
            set { room = String.Copy(value); }
        }


        public int Price
        {
            get { return price; }
            set { price = value; }
        }

        public int ID
        {
            get { return id; }
            set { id = value; }
        }

        public TimeSlot Time
        {
            get { return time; }
        }


        public override String ToString()
        {
            return ("You have an appointmet for: " + therName + "\r\r\nWith: "
                + rmtName + "\r\r\nAt: " + time.startTime.ToShortTimeString()
                + " to " + time.endTime.ToShortTimeString() + "\r\r\nIn room: "
                + room + "\r\r\nTotal: $" + price);
        }


        public override bool Equals(object obj)
        {
            if (obj is Appointment)
                return (this.RMTName == ((Appointment)obj).RMTName &&
                        this.TherapyName == ((Appointment)obj).TherapyName &&
                        this.Time.Equals(((Appointment)obj).Time));
            else return false;
        }

        /*
         * Write the information for this appointment to the database
         */
        public int writeToDatabase(Database db)
        {
            this.ID = db.writeAppointment(this);
            return this.ID;
        }
    }
}

